package org.example.chat;


import org.example.chat.websocket.WSServer;
import org.example.chat.config.ServerConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.annotation.PostConstruct;

/**
 * @author cheval
 */
//@EnableDiscoveryClient
@EnableConfigurationProperties({ServerConfigProperties.class, ServerConfigProperties.WsProperties.class,
        ServerConfigProperties.CacheProperties.class})
@SpringBootApplication
public class ChatServer {

    @Autowired
    private WSServer wsServer;
    @Autowired
    private ThreadPoolTaskExecutor executor;

    public static void main(String[] args) {
        SpringApplication.run(ChatServer.class);
    }


    @PostConstruct
    public void init() {
        startWsServer();
    }


    /**
     * 启动websocket服务
     */
    public void startWsServer() {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                wsServer.start();
            }
        });
    }
}
